package Scripting;

import DEC.DEC;
import java.io.File;

/**
 *
 * @author mgrutman
 */
public class TheScript 
{
    public void mainScript ()
    {
        System.out.println("choose a script:");
        System.out.println("1. First time setup (manufacturing)");
        System.out.println("2. Dynamicaly change configuration");
        System.out.println("3. Hardware change");
        
        String str = DEC.readInput ();
        int choice = Integer.parseInt(str);

        switch (choice)
        {
            case 1: firstTimeScript ();
                break;
                
            case 2: dynamicChange ();
                break;
                
            default: System.out.println("Unknown option -> " + str);
        }        
    }

    private void firstTimeScript()
    {
        int state = 0;
        int res = 0;

        MainL:
        while (true)
        {
            switch (state)
            {
                case 0: res = askConnectSerialLineSwitch ();    break;
                case 1: res = initEthernetSwitch ();            break;
                case 2: res = rebootEtherentSwitch ();          break;
                case 3: res = chooseConfiguration ();           break;
                case 4: res = testComponents ();                break;
                case 5: res = setupEthernetSwitch ();           break;
                case 6: res = pingEthernetSwitch ();            break;
                case 7: res = pingIBSwitch ();                  break;
                case 8: res = setupIBSwitch ();                 break;
                case 9: res = connectMMCS ();                   break;
                case 10: res = configAndInstall ();             break;
                    
                case 11: break MainL;
            }
            
            if (res != 0)
                break;
            state++;
        }        
    }

    private void dynamicChange()
    {
        int state = 0;
        int res = 0;

        MainL:
        while (true)
        {
            switch (state)
            {
                case 0: res = userLogin ();                     break;
                case 1: res = displayAvailableResources ();     break;
                case 2: res = chooseConfiguration ();           break;
                case 3: res = testComponents ();                break;
                case 4: res = setupEthernetSwitch ();           break;
                case 5: res = pingEthernetSwitch ();            break;
                case 6: res = pingIBSwitch ();                  break;
                case 7: res = setupIBSwitch ();                 break;
                case 8: res = connectMMCS ();                   break;
                case 9: res = configAndInstall ();              break;
                    
                case 10: break MainL;
            }
            
            state++;
        }        
    }
    
    private int userLogin ()
    {
        System.out.println("Enter login name. If this is your first time, the login that you will enter");
        System.out.println("will be used as your permanent login.");
        System.out.println("Login -> ");
        String str = DEC.readInput ();
        
        boolean success = new File("jManagement/users/"+str).mkdirs();
        return 0;
    }
    
    private int displayAvailableResources ()
    {
        return 0;
    }
    
    private int chooseConfiguration ()
    {
        return 0;
    }
    
    private int testComponents ()
    {
        return 0;
    }
    
    private int setupEthernetSwitch ()
    {
        return 0;
    }
    
    private int pingEthernetSwitch ()
    {
        
        return 0;
    }
    
    private int pingIBSwitch ()
    {
        return 0;
    }
    
    private int setupIBSwitch ()
    {
        return 0;
    }
    
    private int connectMMCS ()
    {
        return 0;
    }
    
    private int configAndInstall ()
    {
        return 0;
    }
    
    private int askConnectSerialLineSwitch ()
    {
        System.out.println("Connect serial cable to the Ethernet switch.");
        System.out.println("Hit <CR> when ready");
        DEC.readInput ();
        return 0;
    }
    
    private int initEthernetSwitch ()
    {
        System.out.println("Enter the following lines:");
        System.out.println("add ip interface=vlan2 ipaddress=192.168.176.176 netmask 255.255.255.0");
        System.out.println("add ip interface=vlan2 ipaddress=192.168.177.177 netmask 255.255.255.0");
        System.out.println("restart switch");
        System.out.println("Hit <CR> when ready");
        DEC.readInput ();
        return 0;
    }
    
    private int rebootEtherentSwitch ()
    {
        return 0;
    }
    

}
